using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data;

namespace BondedWareHouse
{
     class  clsDBAccess
    {
        
        private static OleDbTransaction m_Tran=null;
        private static OleDbConnection m_Cnn;


        public clsDBAccess(string ConnString)
        {
            m_Cnn  = new OleDbConnection(ConnString);

        }
        public  void BeginTransaction()
        {
            try
            {
                if (m_Cnn.State == ConnectionState.Closed)
                    m_Cnn.Open();
                m_Tran = m_Cnn.BeginTransaction();

            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public  void Commit()
        {
            try
            {
                m_Tran.Commit();

                m_Tran = null;

            }
            catch (Exception e)
            {
                throw e;
            }

        }
        public  void RollBack()
        {
            try
            {
                m_Tran.Rollback();
                m_Tran = null;
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        public  DataSet ReadTable(string strSQL)
        {

            try
            {
                OleDbCommand cmm = new OleDbCommand();
                OleDbDataAdapter da = new OleDbDataAdapter();
                DataSet ds = new DataSet();

                if (m_Cnn.State == ConnectionState.Closed)
                    m_Cnn.Open();
                cmm.CommandType = CommandType.Text;
                cmm.Connection = m_Cnn;
                cmm.CommandText = strSQL;
                if (m_Tran != null)
                    cmm.Transaction = m_Tran;
                da.SelectCommand = cmm;
                da.Fill(ds);
                return ds;
            }
            catch (Exception e)
            {
                throw e;
            }
            

        }
        public  bool ExecSQL(string strSQL)
        {
            try
            {
                OleDbCommand cmm = new OleDbCommand();
                cmm.CommandType = CommandType.Text;
                cmm.CommandText = strSQL;
                cmm.Connection = m_Cnn;
                if (m_Tran != null)
                    cmm.Transaction = m_Tran;
                if (m_Cnn.State == ConnectionState.Closed)
                    m_Cnn.Open();
                cmm.ExecuteNonQuery();
                return true;
            }
            catch (Exception e)
            {
                throw e;
              //  return false;
                
            }
        }

    }
}
